export * from './validate'
import { ElMessage } from 'element-plus'

export const PlainMessage = (option, type = 'info') => {
  const props = {
    message: '',
    type,
    plain: true
  }

  typeof option === 'object'
    ? Object.assign(props, option)
    : (props.message = option)

  return ElMessage(props)
}

PlainMessage.success = option => PlainMessage(option, 'success')
PlainMessage.error = option => PlainMessage(option, 'error')
PlainMessage.warning = option => PlainMessage(option, 'warning')
PlainMessage.info = option => PlainMessage(option, 'info')

export const fileCategory = {
  image: 'image',
  video: 'video',
  audio: 'audio',
  doc: 'doc',
  text: 'text',
  pdf: 'pdf',
  excel: 'excel',
  others: 'others'
}

const getFileExtension = filename => {
  return filename.split('.').pop().toLowerCase()
}

export const determineFileType = filename => {
  const ext = getFileExtension(filename)

  if (['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'].includes(ext))
    return fileCategory.image
  if (['mp4', 'webm', 'mov', 'avi'].includes(ext)) return fileCategory.video
  if (['mp3', 'wav', 'ogg', 'flac'].includes(ext)) return fileCategory.audio
  if (
    ['txt', 'log', 'json', 'js', 'ts', 'html', 'css', 'vue', 'md'].includes(ext)
  )
    return fileCategory.text
  if (['pdf'].includes(ext)) return fileCategory.pdf
  if (['docx'].includes(ext)) return fileCategory.doc
  if (['xls', 'xlsx'].includes(ext)) return fileCategory.excel

  return fileCategory.others
}
